from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLineEdit, QPushButton
from PySide6.QtGui import QIntValidator

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('无限制整数输入')
        layout = QVBoxLayout()

        # 创建一个QLineEdit并设置QIntValidator来限制输入为整数
        self.input = QLineEdit()
        # 设置验证器，这里不设置范围，允许任意整数输入
        validator = QIntValidator()
        self.input.setValidator(validator)
        layout.addWidget(self.input)

        # 添加一个按钮来演示如何获取输入值
        button = QPushButton('获取输入')
        button.clicked.connect(self.getInput)
        layout.addWidget(button)

        self.setLayout(layout)

    def getInput(self):
        # 获取输入并处理，这里简单地打印出来
        value = self.input.text()
        if value:
            print(f"输入的整数是: {value}")
        else:
            print("没有输入")


if __name__ == '__main__':
    app = QApplication([])
    window = Window()
    window.show()
    app.exec_()